package com.grt192.core;

import java.awt.Graphics;
import java.awt.Point;
import java.util.ArrayList;

import simulator.Environment;
import simulator.PhysicalObject;

/**
 * A SimultatedSensor is a virtual sensor, that abstracts it's position on the
 * robot, as well as the robot's position in the environment(angular as well).
 * It also abstracts Physical object detection for the RangeFinder
 * implementation
 * 
 * @author ajc
 * 
 */
public abstract class SimulatedSensor extends NewSensor {

	/**
	 * Sensor's environment, or where the sensor is taking readings
	 */
	private final Environment env;
	/**
	 * Position wrt Robot of this sensor
	 */
	private final Point position;

	/**
	 * Constructs a SimulatedSensos
	 * 
	 * @param env
	 *            Environment where this Sensor is detecting
	 * @param position
	 *            sensor's position on the robot
	 */
	public SimulatedSensor(Environment env, Point position) {
		this.env = env;
		this.position = position;
	}

	/**
	 * 
	 * @return this sensor's relative x position to the robot
	 */
	protected int x() {
		return position.x;
	}

	/**
	 * 
	 * @return this sensor's relative y position to the robot
	 */
	protected int y() {
		return position.y;
	}

	/**
	 * 
	 * @return the robot's absolute x position
	 */
	protected double robotX() {
		return env.getRobotX();
	}

	/**
	 * 
	 * @return the robot's absolute y position
	 */
	protected double robotY() {
		return env.getRobotY();
	}

	/**
	 * 
	 * @return the robot's angular position
	 */
	protected double robotHeading() {
		return env.getRobotAngle();
	}

	/**
	 * Gets all the physical objects in range of this Sensor
	 */
	protected ArrayList<PhysicalObject> getPhysicalObjects(double range) {
		// TODO magic number
		return env.getLocalObjects((env.getRobotX() + position.x),
				(env.getRobotY() + position.y), range);
	}

	/**
	 * Displays this sensor in the Simulator
	 * 
	 * @param g
	 */
	public abstract void paint(Graphics g);
}
